<?php
namespace Api\Plugin\InviteStrategy;

use Api\Plugin\AbstractInviteStrategy;
use Base\ConstDir\Api\ApiError;

class RewardStrategy extends AbstractInviteStrategy{
    private $_rewardBonusCategoryId = 18; // 奖励的优惠劵分类id, 该优惠劵适用于非玻璃宝的所有保障型商品

    /**
     * 被邀请人在一个月内购买产品(除玻璃宝), 且验车成功, 邀请者可获得50元账户余额
     */
    public function run($options = array()){


        parent::run($options);

        // 被邀请者奖励50元代金券
        $bonusCategory = $this->sm->get('Api\Model\BonusCategory')->select(array('BonusCategoryID' => $this->_rewardBonusCategoryId))->current();
        $bonusData = array(
            'BonusCategoryID' => $bonusCategory['BonusCategoryID'],
            'MemberID' => $this->_memberID,
            'BonusName' => $bonusCategory['CategoryName'],
            'BonusMoney' => $bonusCategory['BonusMoney'],
            //'ExpireTime' => $bonusCategory['ExpireTime'],
            'ExpireTime' => $bonusCategory['ValidDays'] * 24 * 3600 + time(),
            'InviterID' => $this->_inviterInfo['MemberID'],
        );

        return  $this->sm->get('Api\Model\MemberBonus')->insert($bonusData);
    }
}